package demo3;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-04-11
 * Time: 14:04
 */
class Person {
      public int age;
      public String name;
      public double score;

    public Person(int age, String name, double score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
//需要重写hashcode和equals
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Double.compare(person.score, score) == 0 && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name, score);
    }
}

public class TestDemo4 {
    public static void main(String[] args) {
       Person person1 = new Person(18,"张三",78.8);
       Person person2 = new Person(18,"张三",78.8);
       System.out.println(person1.equals(person2));
        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
    }

}
